package com.jmcgg.freesky.common.util;

public class StringUtil extends FreeskyUtil {
	public static String fillPreZero(int length, String str) {
		String ret = str == null ? "" : str.trim();
		if (ret.length() > length) {
			return ret;
		} else {
			while (ret.length() < length) {
				ret = "0" + ret;
			}
			return ret;
		}
	}

	public static String fillPreZero(int length, int num) {
		return fillPreZero(length, String.valueOf(num));
	}

	public static String fillPreZero(int length, long num) {
		return fillPreZero(length, String.valueOf(num));
	}

	public static String removePreZero(String str) {
		String ret = str == null ? "" : str.trim();
		while (ret.substring(0, 1).equals("0")) {
			if (ret.length() > 1)
				ret = ret.substring(1, ret.length());
		}
		return ret;
	}

	public static String fillPostZero(int length, String str) {
		String ret = str == null ? "" : str.trim();
		if (ret.length() > length) {
			return ret;
		} else {
			while (ret.length() < length) {
				ret += "0";
			}
			return ret;
		}
	}

	public static String removePostZero(String str) {
		String ret = str == null ? "" : str.trim();
		while (ret.substring(ret.length() - 1, ret.length()).equals("0")) {
			if (ret.length() > 1)
				ret = ret.substring(0, ret.length() - 1);
		}
		return ret;
	}

}
